<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/bootstrap/img/favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrap/css/style.min.css?v=4.0.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css"/>
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet"/>
<title>病人端管理</title>
</head>
<body>
	<div class="panel panel-default">
	    <div class="panel-body form-group" style="margin-top: 0px;">
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">所属城市：</label>
	        <div class="col-sm-2">
	            <select class="form-control" name="useradrprovince" id="useradrprovince1" onchange="loadcity()">
					<option value="0">---请选择省---</option>
				</select>
	        </div>
	        <div class="col-sm-2">
	            <select class="form-control" name="useradrcity" id="useradrcity1" onchange="loadarea()">
					<option value="0">---请选择市---</option>
				</select>
	        </div>
	        <div class="col-sm-2">
	            <select class="form-control" name="useradrarea" id="useradrarea1">
					<option value="0">---请选择区（县）---</option>
				</select>
	        </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">年龄大于：</label>
	        <!-- <div class="col-sm-2">
	            <input type="text" class="form-control" name="docage" id="docage"/>
	        </div> -->
	        <div class="col-sm-1 form-group">
            	<div class="input-daterange input-group" id="docage">
                	<input type="text" class="input-md form-control" name="userage" id="userage1" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"/>
            		<span class="input-group-addon">岁</span>
            	</div>
            </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">审核情况：</label>
	        <div class="col-sm-2">
	            <select class="form-control" name="type" id="type">
					<option value="0">全部</option>
					<option value="1">未审核</option>
					<option value="2">等待审核</option>
					<option value="3">已审核</option>
					<option value="4">未通过审核</option>
				</select>
	        </div>
	    </div>
	    <div class="panel-body form-group" style="margin-top: 0px;">
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">注册手机号：</label>
	        <div class="col-sm-2">
	            <input type="text" class="form-control" name="userloginphone" id="userloginphone1"/>
	        </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">审核提交时间：</label>
	        <div class="col-sm-3 form-group">
                <div class="input-daterange input-group" id="datepicker">
                    <input type="text" class="input-md form-control" id="startdatetime" name="startdatetime" value="" />
                    <span class="input-group-addon">到</span>
                    <input type="text" class="input-md form-control" id="enddatetime" name="enddatetime" value="" />
                </div>
            </div>
            <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">病人性别：</label>
	        <div class="col-sm-1">
	            <select class="form-control" name="usermale" id="usermale1">
					<option value="">全部</option>
					<option value="男">男</option>
					<option value="女">女</option>
				</select>
	        </div>
	        <div class="col-sm-1 control-label">
	            <button class="btn btn-primary" id="search_btn">查询</button>
	        </div>
	     </div>
	</div>
	<!-- 动态加载table -->
	<table id="patienttab" class="table table-hover"></table>
	<div class="modal inmodal fade" id="PatientDetailsModal" tabindex="-1" role="dialog"  aria-hidden="true">
    	<div class="modal-dialog" style="width: 1200px;">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">用户详情</h4>
               	</div>
                <div class="modal-body">
                	<div class="wrapper wrapper-content">
        				<div class="row animated fadeInRight">
                    		<div class="col-sm-4">
                				<div class="ibox float-e-margins">
                    				<div class="ibox-title">
				                        <h4>个人登陆资料</h4>
				                    </div>
				                    <div>
				                    	<div class="ibox-content profile-content">
			                    			<img alt="image" id="userloginpix" style="max-width:100px" class="img-rounded" src="${pageContext.request.contextPath}/bootstrap/img/a5.jpg">
			                    		</div>
			                    		<div class="ibox-content profile-content">
			                    			<p><i class="fa fa-user"> 登陆手机号码：</i><strong><a id="userloginphone"></a></strong></p>
				                            <hr/>
				                            <p><i class="fa fa-user"> 登陆账号审核状态：</i><strong><a id="userlogintypename"></a></strong></p>
				                            <hr/>
				                            <p><i class="fa fa-map-marker"> 上次登陆时间：</i><strong><a id="userlogintime"></a></strong></p>
				                            <hr/>
			                    		</div>
				                    </div>
				                </div>
				        	</div>
				        	<div class="col-sm-8">
                				<div class="ibox float-e-margins">
                    				<div class="ibox-title">
				                        <h4>个人详细信息</h4>
				                    </div>
				                    <div class="ibox-content">
			                    		<div class="row">
			                    			<div class="col-sm-6">
			                    				<p><i class="fa fa-user"> 真实姓名：</i><strong><a id="username"></a></strong></p>
												<hr/>
						                    	<p><i class="fa fa-credit-card"> 身份证号码：</i><strong><a id="usercardnum"></a></strong></p>
						                 		<hr/>
						                 		<p><i class="fa fa-credit-card"> 所在地址：</i><strong><a id="address1"></a></strong></p>
						                 		<hr/>
			                    			</div>
			                    			<div class="col-sm-6">
			                    				<p><i class="fa fa-user"> 性别：</i><strong><a id="usermale"></a></strong></p>
						                    	<hr/>
						                    	<p><i class="fa fa-user"> 年龄：</i><strong><a id="userage"></a></strong></p>
						                    	<hr/>
						                 		<p><i class="fa fa-credit-card"> 所在区和路：</i><strong><a id="address2"></a></strong></p>
						                 		<hr/>
			                    			</div>
			                    			<!-- 显示照片 -->
			                    			<div id="photoPanel">
			                    				
			                    			</div>
			                    		</div>
				                    </div>
				                </div>
				        	</div>
        				</div>
        			</div>
                </div>
				<div class="modal-footer">
                	<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
           		</div>
           	</div>
        </div>
	</div>
	
	<div class="modal inmodal fade" id="EditModal" tabindex="-1" role="dialog"  aria-hidden="true">
    	<div class="modal-dialog modal-lg" style="width:800px;">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">编辑病人信息</h4>
               	</div>
                <div class="modal-body">
                	<div class="row">
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">病人姓名：</label>
		                        <input type="text" name="username" id="Eusername" class="form-control" placeholder="病人姓名">
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">病人性别：</label>
		                    	<select class="form-control" name="usermale" id="Eusermale">
		                        	<option value="女">女</option>
		                        	<option value="男">男</option>
								</select>
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">病人年龄：</label>
		                        <input type="text" name="userage" id="Euserage" class="form-control" placeholder="病人年龄">
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">身份证号码：</label>
								<input type="text" name="usercardnum" id="Eusercardnum" class="form-control" placeholder="病人身份证号码">
		                   	</div>
                		</div>
                		<div class="col-sm-12">
                			<div class="form-group draggable">
		                    	<label class="control-label">病人详细地址：</label>
		                        <input type="text" name="useradr" id="Euseradr" class="form-control" placeholder="病人详细地址">
		                        <input type="hidden" id="Euseradrprovince"/><input type="hidden" id="Euseradrcity"/>
		                        <input type="hidden" id="Euseradrarea"/><input type="hidden" id="Euseradrother"/>
		                        <input type="hidden" id="Euseradrlon" value="117.171056"/><input type="hidden" id="Euseradrlat" value="31.833742"/>
		                   	</div>
                		</div>
                	</div>
                </div>
				<div class="modal-footer">
                	<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                	<button type="button" class="btn btn-primary" onclick="userinfoSubmit();" id="userinfoBtn">提交</button>
           		</div>
           	</div>
        </div>
	</div>
	
	<div class="modal fade" id="myMapModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
		<div class="modal-dialog" style="width: 1000px;height:800px;">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
					<h4 class="modal-title" id="myModalLabel"><a>百度地图选点(鼠标滑动放大缩小地图,左击拖动移动地图。点击获取经纬度)</a></h4>
				</div>
				<div class="modal-body" id="map_main" style="height:500px;">地图容器</div>
				<div class="modal-footer">
					<input style="width:300px;float:left;" type="text" placeholder="左击地点，生成经纬度" value="" id="map_txt" class="form-control" readonly=""/>
					<!-- 经度 -->
					<input type="hidden" id="lng"/>
					<!-- 纬度 -->
					<input type="hidden" id="lat"/>
					<!-- 省 -->
					<input type="hidden" id="province"/>
					<!-- 市 -->
					<input type="hidden" id="city"/>
					<!-- 区 -->
					<input type="hidden" id="area"/>
					<!-- 街 -->
					<input type="hidden" id="other"/>
					<button type="button" class="btn btn-primary" onclick="setMapValue()" data-dismiss="modal">设置为此地址</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-confirm.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/moment-with-locales.min.js"></script>
	<script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
	<script src="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2d12993ce41407db4050140fe342d9ba"></script>
    <script>
      //根据窗口调整表格高度
        $(window).resize(function() {
            $('#patienttab').bootstrapTable('resetView', {
                height: tableHeight()
            })
        })
        //查询按钮事件
        $('#search_btn').click(function(){
            $('#patienttab').bootstrapTable('refresh',{url: '${pageContext.request.contextPath}/Main/Patient/patientListAjax.action'});
        })
        //tableHeight函数
        function tableHeight(){
            //可以根据自己页面情况进行调整
            return $(window).height();
        }
      	function refreshTab(){
      		$('#patienttab').bootstrapTable('refresh');
      	}
    	//生成用户数据
        $('#patienttab').bootstrapTable({
            method: 'get',
            contentType: "application/x-www-form-urlencoded",//必须要有！！！！
            url:"${pageContext.request.contextPath}/Main/Patient/patientListAjax.action",//要请求数据的文件路径
            height:tableHeight(),//高度调整
            striped: true, //是否显示行间隔色
            dataField: "rows",//bootstrap table 可以前端分页也可以后端分页，这里
            //我们使用的是后端分页，后端分页时需返回含有total：总记录数,这个键值好像是固定的  
            //rows： 记录集合 键值可以修改  dataField 自己定义成自己想要的就好
            pageNumber: 1, //初始化加载第一页，默认第一页
            pagination:true,//是否分页
            queryParamsType:'limit',//查询参数组织方式
            queryParams:function(params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的    
                return {//这里的params是table提供的    
                    offset : params.offset,//从数据库第几条记录开始    
                    limit : params.limit,
                    type:$('#type').val(),
                    useradrprovince:$('#useradrprovince1').val(),
                    useradrcity:$('#useradrcity1').val(),
                    useradrarea:$('#useradrarea1').val(),
                    userage:$('#userage1').val(),
                    userloginphone:$('#userloginphone1').val(),
                    startdatetime:$('#startdatetime').val(),
	                enddatetime:$('#enddatetime').val(),
	                usermale:$('#usermale1').val()
                //找多少条    
                };},//请求服务器时所传的参数
            sidePagination:'server',//指定服务器端分页
            pageSize:10,//单页记录数
            pageList:[1,5,10,30,50,100],//分页步进值
            showRefresh:true,//刷新按钮
            showColumns:true,
            clickToSelect: true,//是否启用点击选中行
            toolbarAlign:'right',//工具栏对齐方式
            buttonsAlign:'right',//按钮对齐方式
            toolbar:'#toolbar',//指定工作栏
            columns:[
                {
                    title:'全选',
                    field:'select',
                    //复选框
                    checkbox:true,
                    width:25,
                    align:'center',
                    valign:'middle'
                },
                {
                    title:'病人端登陆ID',
                    field:'userloginid'
                },
                {
                    title:'病人姓名',
                    field:'username'
                },
                {
                    title:'病人性别',
                    field:'usermale'
                },
                {
                    title:'病人登陆手机号',
                    field:'userloginphone'
                },
                {
                    title:'病人注册身份证号码',
                    field:'usercardnum'
                },
                {
                    title:'病人端账户状态',
                    field:'userlogintypename'
                },
                {
                    title:'操作',
                    field:'userlogintype',
                  	//列数据格式化
                    formatter:operate
                },
            ],
            locale:'zh-CN',//中文支持,
            responseHandler:function(rows){
                //在ajax获取到数据，渲染表格之前，修改数据源
                return rows;
            }
        })
        //操作序列规则化
		function operate(value,row,index){
        	return '<button class="btn btn-primary" style="height:30px" onclick="Details('+row.userloginid+')">详情</button>&nbsp;&nbsp;<button class="btn btn-info" style="height:30px" onclick="EditInfo('+row.userloginid+')">编辑</button>';
		}
        function Details(userloginid){
    		//alert(userloginid);
    		$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/Main/Patient/getPatientDetails.action",
				data:"userloginid="+userloginid,
				async: true,
	    		success:function(data){
	    			//alert("data.details.docname="+data.details.docname);
	    			if(data.code==100){
	    				$('#PatientDetailsModal').modal('show');
	    				ModalPadding(data.details);
	    			}else{
	    				$.alert(""+data.msg);
	    			}
	    		},error:function(request){
	    			
	    		}
			})
    	}
        
        function EditInfo(userloginid){
	    	//alert(hosploginid);
	    	$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/Main/Patient/getPatientDetails.action",
				data:"userloginid="+userloginid,
				async: true,
	    		success:function(data){
	    			//alert("data.details.docname="+data.details.docname);
	    			if(data.code==100){
	    				var details=data.details;
	    				$("#EditModal").modal('show');
	    				$("#Eusername").val(details.username);//
	    				$("#Euserage").val(details.userage);//
	    				$("#Eusermale").val(details.usermale);//
	    				$("#Eusercardnum").val(details.usercardnum);//
	    				$("#Euseradr").val(details.useradrprovince+":"+details.useradrcity+":"+details.useradrarea+":"+details.useradrother);//+":"+details.useradrlon+":"+details.useradrlat
	    				$("#Euseradrprovince").val(details.useradrprovince);
	    				$("#Euseradrcity").val(details.useradrcity);
	    				$("#Euseradrarea").val(details.useradrarea);
	    				$("#Euseradrother").val(details.useradrother);
	    			}else{
	    				$.alert(""+data.msg);
	    			}
	    		},error:function(request){
	    			$.alert("病人信息加载失败");
	    		}
			})
	    }
        function userinfoSubmit(){
        	var username = $("#Eusername").val();//
			var userage = $("#Euserage").val();//
			var usermale = $("#Eusermale").val();//
			var usercardnum = $("#Eusercardnum").val();//
			var useradrprovince = $("#Euseradrprovince").val();
			var useradrcity = $("#Euseradrcity").val();
			var useradrarea = $("#Euseradrarea").val();
			var useradrother = $("#Euseradrother").val();
			var param="username="+username+"&userage="+userage+"&usermale="+usermale+"&usercardnum"+usercardnum+
					"&useradrprovince="+useradrprovince+"&useradrcity="+useradrcity+"&useradrarea="+useradrarea+"&useradrother="+useradrother;
			$.confirm({
	    		title: '提示!',
    		    content: '您确定要提交保存？',
    		    type: 'blue',
    		    typeAnimated: true,
    		    buttons: {
    		    	确定: function () {
    		    		$("#userinfoBtn").html('<i class="fa fa-spinner fa-spin"></i>处理中...');
    		    		$("#userinfoBtn").prop('disabled',true);
    		    		$.ajax({
    		    			type:"post",
    		    			url:"${pageContext.request.contextPath}/Main/Patient/patientinfoSubmit.action",
    		    			data:param,
    		    			async: true,
    		    			success:function(data){
    		    				$("#userinfoBtn").html('提交');
    	    		    		$("#userinfoBtn").prop('disabled',false);
    		        			$.alert(data.msg);
    		    				if(data.code==100){
    		    					$('#EditModal').modal('hide');
    		        				refreshTab();
    		    				}
    		    			},error:function(request){
    		    				$("#userinfoBtn").html('提交');
    	    		    		$("#userinfoBtn").prop('disabled',false);
    		        			$.alert("向服务器请求失败！");
    		    			}
    		    		});
    		    	},
    		    	取消:function(){},
    		    }
	    	})
        }
        
    	function ModalPadding(data){
	    	$("#userloginpix").attr('src',data.userloginpix);//登陆头像
			$("#userloginphone").html(data.userloginphone);//登录手机号码
			$("#userlogintypename").html(data.userlogintypename);//账号登陆状态字
			$("#userlogintime").html(data.userlogintime);//上次登陆时间
			
			$("#username").html(data.username);//医院名称
			$("#userage").html(data.userage);//
			$("#usermale").html(data.usermale);//
			$("#usercardnum").html(data.usercardnum);//
			$("#address1").html(data.useradrprovince+","+data.useradrcity);//所在地址
			$("#address2").html(data.useradrarea+","+data.useradrother);//所在地址
			for(var i=0;i<data.usercardphoto.length;i++){
				var usercardphoto=data.usercardphoto[i];
				var photoname="病人身份证照片*"+Number(i+1);
				if(usercardphoto!=""){
					AddPhotoPanel(usercardphoto,photoname);
				}
			}
	    }
    	function AddPhotoPanel(data,photoname){
        	$("#photoPanel").append('<div class="col-sm-6">'+
    		    	'<div class="panel panel-default">'+
    		    	'<div class="panel-heading">'+
    	            	'<h5 class="panel-title">'+
    	                	'<a data-toggle="collapse" data-parent="#accordion" href="javscript:;">'+photoname+'</a>'+
    	            	'</h5>'+
    	            '</div>'+
    	     		'<div id="" class="panel-collapse collapse in">'+
                    	'<div class="panel-body">'+
                           	'<a class="fancybox" target="_blank" href="'+data+'" title="'+photoname+'">'+
    				        	'<img alt="image" src="'+data+'" style="width:320px;height:180px;"/>'+
    					    '</a> '+
                		'</div>'+
                	'</div>'+
               ' </div>'+
        	'</div>');
        }
	</script>
	<script type="text/javascript">
		$(function () {
			$('#startdatetime').datetimepicker({  
				format: 'YYYY-MM-DD',  
				locale: moment.locale('zh-cn')  
			});
			$('#enddatetime').datetimepicker({  
				format: 'YYYY-MM-DD',  
				locale: moment.locale('zh-cn')  
			});
			$.ajax({
    			type:"post",
    			url:"${pageContext.request.contextPath}/Main/Patient/loadcity.action",
    			async: true,
    			data:"cityparentcode=0",
        		success:function(data){
        			//alert("data.details.docname="+data.details.docname);
        			if(data.code==100){
        				var datalist = data.list;
                        for (var i = 0; i < datalist.length; i++) {  
                            $('#useradrprovince1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }
        			}else{
        				$.alert(data.msg);
        			}
        		},error:function(){
        			$.alert("加载省失败!!!");
        		}
    		})
		});
		function loadcity(){
			var cityparentcode = $("#useradrprovince1").val();
			if(cityparentcode==0){
				$("#useradrcity1").empty();  
                $("#useradrarea1").empty();
                $('#useradrcity1').append("<option value='0' selected='selected' >" + '---请选择市---' + "</option>");  
                $('#useradrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
			}else{
				$("#useradrcity1").empty();  
                $("#useradrarea1").empty();
                $.ajax({  //页面首加载省下拉框数据
                    type: "post",  
                    url: "${pageContext.request.contextPath}/Main/Patient/loadcity.action",
            		async: true,
                    data:"cityparentcode="+cityparentcode,
                    success: function (data) {
                    	var datalist = data.list;
                    	$('#useradrcity1').append("<option value='0' selected='selected' >" + '---请选择市---' + "</option>");  
                        $('#useradrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
                        for (var i = 0; i < datalist.length; i++) {
                            $('#useradrcity1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }  
                    },  
                    error: function () {  
                        $.alert("加载市失败!!!");  
                    }  
                });
			}
		}
		function loadarea(){
			var cityparentcode = $("#useradrcity1").val();
			if(cityparentcode==0){
                $("#useradrarea1").empty();
                $('#useradrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
			}else{
                $("#useradrarea1").empty();
                $.ajax({  //页面首加载省下拉框数据
                    type: "post",  
                    url: "${pageContext.request.contextPath}/Main/Patient/loadcity.action",
            		async: true,
                    data:"cityparentcode="+cityparentcode,
                    success: function (data) {
                    	var datalist = data.list;
                        $('#useradrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
                        for (var i = 0; i < datalist.length; i++) {
                            $('#useradrarea1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }  
                    },  
                    error: function () {  
                        $.alert("加载县失败!!!");  
                    }  
                });
			}
		}
	</script>
	<script type="text/javascript">
	$(document).ready(function(){
    	$("#Euseradr").click(function(){
    		$("#myMapModal").modal('show');
             setTimeout(function() {     //添加延时加载。解决问题
                 var map = new BMap.Map("map_main");
                 var myCity = new BMap.LocalCity();
                 var gc = new BMap.Geocoder();  //初始化，Geocoder类
                 myCity.get(function(res){
                     map.centerAndZoom(res.center,res.level);
                     map.enableScrollWheelZoom(); 		// 开启鼠标滚轮缩放，重要！
                     //向地图中添加缩放控件
                 	var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
                 	map.addControl(ctrl_nav);
                         //向地图中添加缩略图控件
                 	var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
                 	map.addControl(ctrl_ove);
                         //向地图中添加比例尺控件
                 	var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
                 	map.addControl(ctrl_sca);
                 	
                     var useradrlon = $("#Euseradrlon").val();
                     var useradrlat = $("#Euseradrlat").val();
                     if(useradrlon!="" && useradrlat!=""){
                    	 var point = new BMap.Point(useradrlon,useradrlat);    
                         var marker = new BMap.Marker(point);        // 创建标注    
                         map.clearOverlays();
                         map.addOverlay(marker);
                     }
                     
                     map.addEventListener("click", function(e){
                         var lng_lat = e.point.lng+','+e.point.lat;
                         var point = new BMap.Point(e.point.lng,e.point.lat);    
                         var marker = new BMap.Marker(point);        // 创建标注  
                         gc.getLocation(point,function(rs){
                        	 var addComp = rs.addressComponents;
                        	 var province = addComp.province;//省  
                             var city = addComp.city;  //市
                             var area = addComp.district;//区
                             var street = addComp.street;//街
                             var streetnumber = addComp.streetNumber;
                             var Str = province+":"+city+":"+area+":"+street+":"+streetnumber;
                             $("#map_txt").val(lng_lat+"/"+Str);  //加入到设置框
                             $("#lng").val(e.point.lng);$("#lat").val(e.point.lat);
                             $("#province").val(province);$("#city").val(city);
                             $("#area").val(area);$("#other").val(street+streetnumber);
                         })
                         map.clearOverlays();
                         map.addOverlay(marker);
                     });
                 });
             },300);
         });
    });	
	function setMapValue(){
		var lng = $("#lng").val();
		var lat = $("#lat").val();
		var province = $("#province").val();
		var city = $("#city").val();
		var area = $("#area").val();
		var other = $("#other").val();
		$("#Euseradrprovince").val(province);
    	$("#Euseradrcity").val(city);
    	$("#Euseradrarea").val(area);
    	$("#Euseradrother").val(other);
    	$("#Euseradrlon").val(lng);
    	$("#Euseradrlat").val(lat);
    	$("#Euseradr").val(province+":"+city+":"+area+":"+other);//+":"+lng+":"+lat
	}
	</script>
</body>
</html>